package com.sita.ptcol.util;

import com.google.common.io.BaseEncoding;
import com.google.common.primitives.Ints;

import java.math.BigDecimal;

/**
 * Created by zhebinwang on 2017/4/1.
 */
public class LatLngUtil {

    public static double fromDu(byte[] du) {

        //度 + 分.小数点/60
        int du10 = Ints.fromByteArray(du);
        //  du10=54529611;
        double duD = du10 / 30000d;

        int doo = ((int) duD) / 60;
        int yu = ((int) duD) % 60;
        double fraction = duD - doo * 60 - yu;
        double fen = yu + fraction;

        return BigDecimal.valueOf(doo + fen / 60d).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static byte[] toDu(double du) {
        int doo = (int) du;

        double fen = (du - doo) * 60d;
        double duD = (doo * 60d + fen) * 30000d;

        int duInt = (int) duD;

        return Ints.toByteArray(duInt);
    }

    public static void main(String [] args){


        //1836.2549
        System.out.println(1800*30000L+36.2549*30000L);
        byte[] data1 = BaseEncoding.base16().decode("0348B526");
        double fa=fromDu(data1);
        System.out.println(fa);
    }



}
